<?php

namespace timestamp;

class TimeStamp
{
	public $timestamp = 0;

	public function __construct(int $timestamp)
	{
		$this->timestamp = $timestamp;
	}

	public function year()
	{
		return date('Y', $this->timestamp);
	}

	public function month()
	{
		return date('m', $this->timestamp);
	}

	public function day()
	{
		return date('d', $this->timestamp);
	}

	public function hour()
	{
		return date('H', $this->timestamp);
	}

	public function minute()
	{
		return date('i', $this->timestamp);
	}

	public function second()
	{
		return date('s', $this->timestamp);
	}

	public function friendly()
	{
		$diff = time() - $this->timestamp;

		if ($diff < 10) {
			return '刚刚';
		} elseif ($diff < 60) {
			return '1分钟前';
		} elseif ($diff <= 1800) {
			return intval($diff / 60) . '分钟前';
		} elseif ($diff <= 3600) {
			return date('i:s', $this->timestamp);
		} else if ($diff <= 86400) {
			return date('H:i:s', $this->timestamp);
		} elseif ($diff <= 604800) {
			return date('D H:i', $this->timestamp);
		} elseif ($diff <= 2419200) {
			return date('m-d H:i', $this->timestamp);
		} else {
			return date('Y-m-d H:i', $this->timestamp);
		}

	}

	public static function now()
	{
		return time();
	}

}
